/*
 * @Author: 一路向阳 tt_sunzhenfeng@163.com
 * @Date: 2024-05-14 23:16:59
 * @LastEditors: 一路向阳 tt_sunzhenfeng@163.com
 * @LastEditTime: 2024-05-15 16:48:17
 * @FilePath: \react_nest_demo\nest_service\src\course\course.controller.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
  Controller,
  Post,
  Body,
  Get,
  Headers,
  Put,
  Delete,
} from '@nestjs/common';
import { CourseService } from './course.service';

import { CreateCourseDto } from './dto/create-course.dto';
import { UpdateCourseDto } from './dto/update-course.dto';
import { DeleteCourseDto } from './dto/delete-course.dto';

import { JwtDecrypTool } from '../utils/internalTools';

@Controller('course')
export class CourseController {
  constructor(
    private readonly courseService: CourseService,
    private readonly jwtDecrypTool: JwtDecrypTool,
  ) {}

  // 课程查找接口
  @Get()
  find(@Headers() headers) {
    this.jwtDecrypTool.getDecryp(headers.authorization);
    return this.courseService.find();
  }

  // 课程创建接口
  @Post()
  create(@Body() createCourseDto: CreateCourseDto, @Headers() headers) {
    this.jwtDecrypTool.getDecryp(headers.authorization);
    return this.courseService.create(createCourseDto);
  }

  // 课程更新接口
  @Put()
  update(@Body() updateCourseDto: UpdateCourseDto, @Headers() headers) {
    this.jwtDecrypTool.getDecryp(headers.authorization);
    return this.courseService.update(updateCourseDto);
  }

  // 课程删除功能
  @Delete()
  delete(@Body() deleteCourseDto: DeleteCourseDto, @Headers() headers) {
    this.jwtDecrypTool.getDecryp(headers.authorization);
    return this.courseService.delete(deleteCourseDto);
  }
}
